import request from '@/utils/request.js'
import query from 'axios';

//提交报名信息
export function applyAdd(data){
    return request({
        url: '/index/apply/index',
        method: 'post',
        data:data
    })
}
//获取报名列表字段

export function applyList(params){
    return request({
        url: '/admin/ApplySelectedField/list',
        method: 'get',
        params:params
    })
}
//获取工种信息

export function applyInit(params){
    return request({
        url: '/admin/platform/init',
        method: 'get',
        params:params
    })
}

//科目表
export function subjectList(params) {
    return new Promise((resolve)=>{
        request({
            url: '/admin/subject/list',
            method: 'get',
            params: '',
        }).then(res=>{
            if(params){
                // console.log(res.data.filter(item=>item.title===params));
                let data = res.data.filter(item=>item.title===params)[0].children || []
                resolve(data)
            }else{
                resolve(res)
            }
        })
    })
}
//培训动态 及 政策法规 列表
 export function articleList(params) {
    return request({
        url: '/admin/article/list',
        method: 'get',
        params:params
    })
}
/**
   * 位置信息请求
   * @param {array} params 请求参数
   */
export function regionList(params) {
    return request({
        url: 'admin/region/regionList',
        method: 'get',
        params: params
    })
}


/**
   * H5支付
   * @param {array} data 请求参数
   */
export function H5Pay(data) {
    return request({
        url: '/index/apply/mph5',
        method: 'get',
        params: data
    })
}
/**
   * 公众号支付
   * @param {array} data 请求参数
   */
export function mpo(data) {
    return request({
        url: '/index/apply/mpo',
        method: 'get',
        params: data
    })
}
/**
   * 支付订单查询
   * @param {array} data 请求参数
   */
export function H5PayList(data) {
    return request({
        url: '/index/apply/findo',
        method: 'get',
        params: data
    })
}
/**
   * 获取openid
   * @param {array} data 请求参数
   */
export function getcode(data) {
    return request({
        url: '/index/login/getcode',
        method: 'get',
        params: data
    })
}
/**
   * 获取openid
   * @param {array} data 请求参数
   */
export function getopenid(data) {
    return request({
        url: '/index/login/getopenid',
        method: 'get',
        params: data
    })
}
/**
   * 查询报名信息
   * @param {array} data 请求参数
   */
export function getapplyInfor(data) {
    return request({
        url: '/index/apply/applylist',
        method: 'get',
        params: data
    })
}
//二维码支付
export function maPay(data){
    return request({
      url:'/index/apply/mpnative',
      method: 'get',
      params:data,
    })
  }
//验证码
export function sendcode(data){
    return request({
      url:'/index/apply/sendcode',
      method: 'post',
      data,
    })
  }

//生成二维码
export function qrcode(data) {
    return request({
      url: '/admin/AdminTool/qrcode',
      method: 'post',
      data
    })
}
//文字识别
export function aliasOCR(data) {
    return request({
      url: '/index/ocr',
      method: 'post',
      data
    })
}
//文字识别
export function photoMake(data) {
    return request({
      url: '/index/photo/make',
      method: 'post',
      data
    })
}
export function Department(params) {
    return request({
      url: '/admin/department/list',
      method: 'get',
      params: params
    })
  }
// .get({
//     url:'https://api.wer.plus/api/taof',
// })
export function axios(url,type,data,resType){
    if(type=='get'){
        return query({
            url: process.env.NODE_ENV === 'development' ?'/backGround' + url:'https://api.wer.plus/api' + url,
            method: type,
            params:data,
            headers:{
                responseType: resType?resType:'application/json'
            }
        })
    }else{
        return query({
            url: url,
            method: type,
            data,
            headers:{
                responseType: resType?resType:'application/json'
            }
        })
    }
} 


export function taof(data){
    return request({
        url: 'index/apply/taof',
        method: 'get',
        params: data
    })
}
//上传
export function upload(data){
    let formData = new FormData
    if(data){
        Object.keys(data).map(item=>{
            formData.append(item,data[item])
        })
    }
    return request(
        {
            url:'/admin/MemberApply/upload',
            method:'post',
            data: formData
        }
    )
}